#include<bits/stdc++.h>
using namespace std;
int t,n,i,j,o,ma=-1;
int f,r,red[80000],blue[80000],dep[80000],p[80000];
int a[2005];
bool qq;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(o=1;o<=t;o++){
        cin>>n;
        for(i=1;i<=n;i++){
            cin>>a[i];
        }
        f=0;r=1;ma=-1;
        red[0]=-1;blue[0]=-1;dep[0]=1;p[0]=0;
        while(f<r){
            if(dep[f]>n){
                if(p[f]>ma){
                    ma=p[f];
                }
                f++;
                continue;
            }

            if(a[dep[f]]==red[f]){
                red[r]=red[f];
                blue[r]=blue[f];
                p[r]=p[f]+red[f];
                dep[r]=dep[f]+1;
                r++;
            }
            else{
                //cout<<"1111111"<<endl;
                p[r]=p[f];
                blue[r]=a[dep[f]];
                red[r]=red[f];
                dep[r]=dep[f]+1;
                r++;
            }
            if(a[dep[f]]==blue[f]){
                p[r]=p[f]+blue[f];
                red[r]=red[f];
                blue[r]=blue[f];
                dep[r]=dep[f]+1;
                r++;
            }
            else{
                //cout<<"2222222"<<endl;
                p[r]=p[f];
                red[r]=a[dep[f]];
                blue[r]=blue[f];
                dep[r]=dep[f]+1;
                r++;
            }
            //cout<<a[dep[f]]<<" "<<dep[f]<<" "<<p[f]<<" "<<red[r]<<" "<<blue[r]<<endl;
            f++;
        }
        cout<<ma<<endl;
    }
}
